package com.dearbinge.opentapi.content.user;

import com.dearbinge.data.api.user.UserAuthenticationManageService;
import com.dearbinge.data.pojo.user.UserAuthenticationManage;
import com.dearbinge.utils.ResultMsg;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Api(description = "用户授权接口")
@RestController
@CrossOrigin
@RequestMapping("/UserAuthenticationManage")
@EnableAutoConfiguration
public class UserAuthenticationManageController extends WebMvcConfigurerAdapter {

    @Autowired
    private UserAuthenticationManageService userAuthenticationManageService;


    /**
     * 新增用户授权接口/修改用户授权接口
     */
    @ApiOperation(value = "新增/修改用户授权接口",notes = "新增/修改用户授权接口")
    @RequestMapping(value = "/addOrUpdate",method = RequestMethod.POST)
    public ResultMsg<String> addOrUpdate(@RequestBody UserAuthenticationManage userAuthenticationManage){
        Integer dataCode = 0;
        try {
            if (userAuthenticationManage.getId() != null && userAuthenticationManage.getId() != 0 ){
                dataCode = userAuthenticationManageService.update(userAuthenticationManage);
                if (dataCode > 0){
                    return ResultMsg.ok("修改成功");
                }
            }else {
                dataCode = userAuthenticationManageService.insert(userAuthenticationManage);
                if (dataCode > 0){
                    return ResultMsg.ok("添加成功");
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultMsg.error(500,"系统异常");
    }


    /**
     * 根据用户id查询认证信息
     */
    @ApiOperation(value = "根据用户id查询认证信息",notes = "根据用户id查询认证信息")
    @ApiImplicitParam(name = "userId",value = "用户id",paramType = "query")
    @RequestMapping(value = "/getUserAuthenticationManageByUserId",method = RequestMethod.GET)
    public ResultMsg<UserAuthenticationManage> getUserAuthenticationManageByUserId( Integer userId){
        try {
        	UserAuthenticationManage userAuthenticationManageByUserId = userAuthenticationManageService.getUserAuthenticationManageByUserId(userId);
        	return ResultMsg.ok(userAuthenticationManageByUserId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultMsg.error(500,"系统异常");
    }

    /**
     * 根据店铺id查询认证信息
     */
    @ApiOperation(value = "根据店铺id查询认证信息",notes = "根据店铺id查询认证信息")
    @ApiImplicitParam(name = "shopId",value = "店铺id",paramType = "query")
    @RequestMapping(value = "/getUserAuthenticationManageByShopId",method = RequestMethod.GET)
    public ResultMsg<UserAuthenticationManage> getUserAuthenticationManageByShopId( Integer shopId){
        try {
        	UserAuthenticationManage userAuthenticationManageByUserId = userAuthenticationManageService.getUserAuthenticationManageByShopId(shopId);
        	return ResultMsg.ok(userAuthenticationManageByUserId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultMsg.error(500,"系统异常");
    }

}
